package blow.sky.quoted.controller;

import blow.sky.quoted.ocr.OcrServiceClient;
import blow.sky.quoted.request.ImgOcrRequest;
import blow.sky.quoted.response.ImgOcrResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Description TODO
 * @Author sun
 * @Date 2021/6/3 22:36
 */

@Validated
@RestController
@RequestMapping("/api/ocr")
public class ImgOcrController
{
    @Autowired
    private OcrServiceClient client;

    @PostMapping("/img")
    public ImgOcrResponse ocrImg(@Valid @RequestBody ImgOcrRequest imgOcrRequest)
    {
        String img = imgOcrRequest.getImg();
        List<List<String>> table = null;
        try {
            table = client.getOcrService().ocr_img(img);
        } catch (Exception e) {
            e.printStackTrace();
            return new ImgOcrResponse("fail", "Unknown Error");
        }
        return new ImgOcrResponse("success", table);
    }
}
